package cn.u313.lymusic.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import cn.u313.lymusic.R;

import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;

public class DlJiluActivity extends AppCompatActivity {
    ListView listView;

    List<DownloadEntity> downloadBean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dl_jilu);

        TextView text000=findViewById(R.id.text00);
        listView=findViewById(R.id.rv_list);
        downloadBean = Aria.download(this).getAllCompleteTask();
        if(downloadBean==null||downloadBean.size()==0){
            text000.setVisibility(View.VISIBLE);

            return;
        }
//        text
        listView.setAdapter(new ArrayAdapter<DownloadEntity>(getApplicationContext(), R.layout.list,downloadBean){
            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {
                View view= LayoutInflater.from(getApplicationContext()).inflate(R.layout.list,parent,false);
                TextView textView=view.findViewById(R.id.text);
                textView.setText(downloadBean.get(position).getFileName());
                LinearLayout linearLayout=view.findViewById(R.id.dlon);
                TextView tn=view.findViewById(R.id.dlno);
                tn.setVisibility(View.VISIBLE);
                tn.setText("已完成");

                textView.setTextColor(Color.BLACK);
                tn.setTextColor(Color.BLACK);
                linearLayout.setVisibility(View.GONE);
                return view;
            }
        });


        //播放
        listView.setOnItemClickListener((parent, view, position, id) -> {
            DownloadEntity downloadEntity = downloadBean.get(position);
            Toast.makeText(this, "文件路径："+downloadEntity.getFilePath(), Toast.LENGTH_SHORT).show();
        });
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish();
                break;
        }
        return true;
    }
}

